#!/usr/bin/env python
import os
import sys
import django

# 设置Django环境
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'inter_api.settings')
django.setup()

from django.contrib.auth import get_user_model
from students.models import Student
from resume_management.models import Resume

User = get_user_model()

def check_resume_content():
    try:
        resume = Resume.objects.get(id=27)
        print(f"简历ID: {resume.id}")
        print(f"简历标题: {resume.title}")
        print(f"简历类型: {resume.resume_type}")
        
        # 检查上传的文件
        if resume.uploaded_file:
            print(f"上传文件: {resume.uploaded_file}")
            print(f"文件路径: {resume.uploaded_file.path}")
            
            # 尝试读取文件内容
            try:
                with open(resume.uploaded_file.path, 'r', encoding='utf-8') as f:
                    content = f.read()
                    print(f"文件内容长度: {len(content)}")
                    print(f"文件内容预览: {content[:200]}...")
            except Exception as e:
                print(f"读取文件失败: {e}")
        else:
            print("没有上传文件")
            
        # 检查生成的文件
        if resume.generated_file:
            print(f"生成文件: {resume.generated_file}")
        else:
            print("没有生成文件")
            
        # 检查结构化数据
        print("\n结构化数据:")
        try:
            basic_info = resume.basicinfo
            print(f"基本信息: {basic_info.name}, {basic_info.email}")
        except:
            print("没有基本信息")
            
        education_list = resume.education_set.all()
        print(f"教育经历数量: {education_list.count()}")
        
        skill_list = resume.skill_set.all()
        print(f"技能数量: {skill_list.count()}")
        
        project_list = resume.project_set.all()
        print(f"项目经历数量: {project_list.count()}")
        
        work_list = resume.workexperience_set.all()
        print(f"工作经历数量: {work_list.count()}")
        
        award_list = resume.award_set.all()
        print(f"获奖情况数量: {award_list.count()}")
        
        try:
            intro = resume.selfintroduction
            print(f"自我介绍存在: {len(intro.content) if intro.content else 0} 字符")
        except:
            print("没有自我介绍")
            
    except Exception as e:
        print(f"检查失败: {e}")
        import traceback
        traceback.print_exc()

if __name__ == '__main__':
    check_resume_content()